﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VideoFileOrganization.BatchRename
{
    public partial class FindAndReplaceFrm : RenameBaseFrm
    {
        public FindAndReplaceFrm()
        {
            InitializeComponent();
            this.Text = "替换字符";
            this.Index = 2;
            this.tabImage = Properties.Resources.recycling;
        }
        /// <summary>
        /// 更新界面
        /// </summary>
        protected override void IniUi()
        {
            cmbHistroy.Items.Clear();
             foreach(string histroy in global.BatchRename.FindAndReplaces)
            {
                cmbHistroy.Items.Add(histroy);
            }
        }

        /// <summary>
        /// 执行按钮
        /// </summary>
        protected override void ExecuteButton()
        {
            BatchRenameClass.tReviseParam param = new BatchRenameClass.tReviseParam();
            param.mode = BatchRenameClass.eReviseMode.REPLACE_THE_CHARACTERS;
            param.subString = new List<string>();
            param.subString.Add(tbxSorce.Text);
            param.subString.Add(tbxTarget.Text);
            OnReviseEvnet(param);
            string add = param.subString[0] + "/" + param.subString[1];
            if (!cmbHistroy.Items.Contains(add))
            {
                cmbHistroy.Items.Add(add);
            }
        }

        private void cmbHistroy_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = cmbHistroy.Text;
            string[]strList = str.Split('/');
            if(strList.Length == 2)
            {
                tbxSorce.Text = strList[0];
                tbxTarget.Text = strList[1];
            }
        }
    }
}
